package com.example.demo.mapper;

import com.example.demo.entity.StudentInfo;
import org.apache.ibatis.annotations.*;
import org.springframework.web.bind.annotation.Mapping;

import java.util.List;

@Mapper
public interface StudentMapper {
    @Select("select * from student_info")
    public List<StudentInfo> getStudentInfo();
    @Select("select * from student_info where stuid= #{id}")
    StudentInfo getStudentInfoById(Integer id);


    @Delete("delete from student_info where stuid= #{id}")
    int deleteStudentInfoById(Integer id);

    @Insert("insert into student_info (stu_no,stu_name,stu_sex,stu_birthday,stu_education,stu_interest,my_color,lucky_number,create_date,clsid) \n" +
            "        values(#{stu_no},#{stu_name},#{stu_sex},#{stu_birthday},#{stu_education},#{stu_interest},#{my_color},#{lucky_number},sysdate(),#{clsid})")
    int insertStudentInfo(StudentInfo studentInfo);

    @Update("UPDATE student_info SET " +
            "stu_no = #{stu_no}, " +
            "stu_name = #{stu_name}, " +
            "stu_sex = #{stu_sex}, " +
            "stu_birthday = #{stu_birthday}, " +
            "stu_education = #{stu_education}, " +
            "stu_interest = #{stu_interest}, " +
            "my_color = #{my_color}, " +
            "lucky_number = #{lucky_number}, " +
            "clsid = #{clsid} " +
            "WHERE stuid = #{stuid}")
    int updateStudentInfo(StudentInfo studentInfo);
    @Select("SELECT * FROM student_info LIMIT #{offset}, #{pageSize}")
    List<StudentInfo> getStudentInfoByPage(@Param("offset") int offset,
                                           @Param("pageSize") int pageSize);

    @Select("SELECT COUNT(*) FROM student_info")
    int countStudentInfo();

}
